package Aleehot100;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: c056
 * Package: Aleehot100
 * Description:78. 子集
 *
 * @Author BCXJ
 * @Create 2025/8/7 08:36
 * @Version 1.0
 * @Since 1.0
 */
public class c056 {

    static List<List<Integer>> res = new ArrayList<>(); // 结果
    public static List<List<Integer>> subsets(int[] nums) {
        res.clear();

        for (int mask = 0; mask < (1 << nums.length); mask++) {
            List<Integer> midRes = new ArrayList<>();// 做 & 运算确定哪个位置的需要放进来
            for (int i = 0; i < nums.length; i++) {
                if((mask & (1 << i)) != 0) {
                    midRes.add(nums[i]);
                }
            }
            res.add(midRes);
        }
        return res;
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3};
        System.out.println(subsets(arr));
    }

    /*
        int n = nums.length;
        for (int mask = 0; mask < (1 << n); ++mask) {
            t.clear();
            for (int i = 0; i < n; ++i) {
                if ((mask & (1 << i)) != 0) {
                    t.add(nums[i]);
                }
            }
            ans.add(new ArrayList<Integer>(t));
        }
        return ans;
     */
}
